<%namespace file="/gmap.html" import="*"/>

<%def name="wpedit()">

<form id="newwaypointform" action="/waypoints/add" method=post>
    <input type=hidden value="${ctx.j.key()}" name=journey>
    <input type=hidden value="${ctx.wp.safe_key()}" name=wp>
<table>

    <tr><td>Arrived</td><td>
    % if ctx.wp.arrived:
        ${h.input_date("arrived", value=ctx.wp.arrived)}
    % else:
        ${h.input_date("arrived")}
    % endif
    </td></tr>
    <tr><td>Leaved</td><td>
    % if ctx.wp.leaved:
        ${h.input_date("leaved", value=ctx.wp.leaved)}
    % else:
        ${h.input_date("leaved")}
    % endif
    </td></tr>
    <tr><td valign=top>Desc</td><td><textarea cols=60 rows=15 name=desc>${ctx.wp.desc|h,ctx.h.enc,h.defnone}</textarea></td></tr>

    <tr><td>Coords</td><td><input type=text name=coords size=37 value="${ctx.wp.coords|ctx.h.defnone}"></td></tr>
    <tr><td>Distance</td><td><input type=text name=distance></td></tr>
    <tr><td>Length</td><td><input type=text name=length></td></tr>

    <tr>
        <td>Icon</td>
        <td><select name=icon>
            <% icons = { 0:"None", 1:"Default icon" } %>
            % for i in icons.keys():
                <option value="${i}"
                % if ( i == ctx.wp.icon ):
                    selected
                % endif
                >${icons[i]}</option>
            % endfor
        </select>
        </td>
    </tr>
    
    <tr>
        <td>Region:</td>
        <td>
            <% rnames = dict() %>
            %if ctx.regions.has_key(0):
                <%rnames[0] = "region"%>
            %endif
            %if ctx.regions.has_key(1):
                <%rnames[0] = "region0"%>
                <%rnames[1] = "region"%>
            %endif
            %if ctx.regions.has_key(2):
                <%rnames[2] = "region"%>
                <%rnames[1] = "region1"%>
            %endif
            %if ctx.regions.has_key(3):
                <%rnames[3] = "region"%>
                <%rnames[2] = "region2"%>
            %endif
            % if ctx.regions.has_key(0):
                <select name="${rnames[0]}" onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[0]:
                    <option value="${r.key()}"
                    %if ctx.wp.region != None and ctx.wp.region.key() == r.key() or ctx.wp.region and ctx.wp.region.get_node(0) and ctx.wp.region.get_node(0).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(1):
                <select name="${rnames[1]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[1]:
                    <option value="${r.key()}"
                    %if ctx.wp.region != None and ctx.wp.region.key() == r.key() or ctx.wp.region and ctx.wp.region.get_node(1) and ctx.wp.region.get_node(1).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(2):
                <select name="${rnames[2]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[2]:
                    <option value="${r.key()}"
                    %if ctx.wp.region != None and ctx.wp.region.key() == r.key() or ctx.wp.region and ctx.wp.region.get_node(2) and ctx.wp.region.get_node(2).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(3):
                <select name="${rnames[3]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[3]:
                    <option value="${r.key()}"
                    %if ctx.wp.region != None and ctx.wp.region.key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
        </td>
    </tr>
    <tr><td colspan=2><input type=submit name=action value=Save></td></tr>
    
</table>
</form>

${wpselector_searchform()|n}

</%def>
